Skip to content

Conversation

@Harshal5
Copy link
Contributor

@Harshal5 Harshal5 commented Apr 8, 2025

Description

Current issue:

As far as I can understand for the psa_mac_ APIs to internally use an external cipher driver we would need to write a custom complete MAC driver. Writing a custom MAC driver would involve almost rewriting the mbedtls_psa_mac_ APIs.

Solution:

Instead we could update the builtin driver's mbedtls_psa_mac_ API usage of mbedtls_cipher_ with psa_cipher_ APIs. This would allow the usage of an external cipher driver with psa_mac_ API calls without rewriting the CMAC code.

Related

Fixes #211

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

@Harshal5 Harshal5 force-pushed the feat/builtin_cmac_driver_use_psa_crypto_interface branch from 8a351f6 to eea13a9 Compare April 8, 2025 02:51
@yanesca yanesca added enhancement New feature or request size-m Estimated task size: medium (~1w) needs-design-approval Needs design discussion / approval labels Apr 9, 2025
@yanesca yanesca moved this from In Development to In Review in Non-roadmap pull requests Apr 9, 2025
@Harshal5 Harshal5 force-pushed the feat/builtin_cmac_driver_use_psa_crypto_interface branch from eea13a9 to e31791f Compare July 9, 2025 04:51
@Harshal5
Copy link
Contributor Author

Harshal5 commented Jul 9, 2025

@gilles-peskine-arm I have now updated the code workflow now, could you PTAL once?

The major change in the current version of the workflow as compared to the earlier one is that instead of adding the PSA_KEY_USAGE_ENCRYPT attribute to the CMAC key, I have now created a new instance/copy of CMAC key with type AES and the encrypt attribute for allowing us to pass the key to the cipher APIs. This key is created in the _mac_start() API and the key id is stored in the operation context, finally is destroyed when _mac_abort() API is called for the operation context (_mac_finish also calls _mac_abort internally).

Therefore, now we do not need the "hack" of adding the encrypt attribute to the CMAC key thus solving the incorrect key policy issue. Also, even if the CMAC API layer holds a lock on the CMAC key, the cipher API layer can use the key for performing encrypt operations and can hold a lock as well.

Here is the current workflow for an PSA CMAC operation that can internally use an external cipher driver as well:
psa_mac_ (PSA API) -> psa_mac_driver_wrapper_ (driver dispatch) -> mbedtls_psa_mac_ (builtin driver) -> psa_cipher_ (PSA API) -> psa_cipher_driver_wrapper_ (driver dispatch) -> mbedtls_psa_cipher_ (builtin driver).

Having this change would also help disabling MBEDTLS_AES_C when using a custom AES driver layer thus reducing the code size significantly.

Let me know what do you think about this approach!

@Harshal5
Copy link
Contributor Author

@gilles-peskine-arm @yanesca Could you PTAL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-design-approval Needs design discussion / approval size-m Estimated task size: medium (~1w)

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Can psa_mac_ APIs internally use an external cipher driver?

2 participants